<?php

require('resultset.php');

class Database
{
	private static $Instance;
	
	public static function GetInstance()
	{
		if (!isset(self::$Instance))
		{
			self::$Instance = new self;
		}
		
		return self::$Instance;
	}
	
	private static $Config;
	
	public static function Config($Config)
	{
		self::$Config = $Config;
	}
	
	private $Connection;
	
	public function __construct()
	{
		$this->Connection = @mysql_connect(self::$Config['Hostname'], self::$Config['Username'], self::$Config['Password']) or die('MySQL Error: ' . mysql_error());
		@mysql_select_db(self::$Config['Database'], $this->Connection) or die('MySQL Error: ' . mysql_error());
	}
	
	public function CloseConnection()
	{
		if (isset($this->Connection))
		{
			mysql_close($this->Connection);
		}
		else
		{
			return false;
		}
	}
	
	public function Query($SqlString)
	{
		return new Resultset($SqlString, $this->Connection);
	}
}